from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.globals import ThemeType

f = open('file/content.txt', 'r', encoding='utf-8')  # 这是数据源，也就是想生成词云的数据

with open('./file/content.txt', mode='r', encoding='utf-8') as f:
    words = f.read()
    name = ["张若昀", "李庚希", "胡军"]
    count = [float(words.count("张若昀")), float(words.count("李庚希")), float(words.count("胡军"))]

num = count
lab = name
(
    Pie(init_opts=opts.InitOpts(width='1650px', height='450px', theme=ThemeType.LIGHT))  # 默认900，600
        .set_global_opts(
        title_opts=opts.TitleOpts(title="雪中悍刀行主演提及占比",
                                  title_textstyle_opts=opts.TextStyleOpts(font_size=27)), legend_opts=opts.LegendOpts(
            pos_top="3%", pos_left="33%",  # 图例位置调整
        ), )
        .add(series_name='', center=[280, 270], data_pair=[(j, i) for i, j in zip(num, lab)])  # 饼图
        .add(series_name='', center=[800, 270], data_pair=[(j, i) for i, j in zip(num, lab)],
             radius=['40%', '75%'])  # 环图
        .add(series_name='', center=[1300, 270], data_pair=[(j, i) for i, j in zip(num, lab)], rosetype='radius')
    # 南丁格尔图
).render('./Html/pie_pyecharts4.html')
